package cn.stylefeng.guns.modular.yingbao.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.yingbao.entity.UserMoneySetting;
import cn.stylefeng.guns.modular.yingbao.model.params.UserMoneySettingParam;
import cn.stylefeng.guns.modular.yingbao.service.UserMoneySettingService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 金额相关设置控制器
 *
 * @author jj
 * @Date 2019-12-23 15:10:31
 */
@Api(tags = "金额相关设置")
@CrossOrigin
@Controller
@RequestMapping("/userMoneySetting")
public class UserMoneySettingController extends BaseController {

    private String PREFIX = "/userMoneySetting";

    @Autowired
    private UserMoneySettingService userMoneySettingService;

    /**
     * 跳转到主页面
     *
     * @author jj
     * @Date 2019-12-23
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/userMoneySetting.html";
    }

    /**
     * 新增页面
     *
     * @author jj
     * @Date 2019-12-23
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/userMoneySetting_add.html";
    }

    /**
     * 编辑页面
     *
     * @author jj
     * @Date 2019-12-23
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/userMoneySetting_edit.html";
    }

    /**
     * 新增接口
     *
     * @author jj
     * @Date 2019-12-23
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(UserMoneySettingParam userMoneySettingParam) {
        this.userMoneySettingService.add(userMoneySettingParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author jj
     * @Date 2019-12-23
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(UserMoneySettingParam userMoneySettingParam) {
        userMoneySettingParam.setFrozenCapital(userMoneySettingParam.getFrozenCapital()*100);
        userMoneySettingParam.setMaxAvailSetting(userMoneySettingParam.getMaxAvailSetting()*100);
        userMoneySettingParam.setMinAvailSetting(userMoneySettingParam.getMinAvailSetting()*100);
        userMoneySettingParam.setMaxExpandSetting(userMoneySettingParam.getMaxExpandSetting()*100);
        userMoneySettingParam.setMinExpandSetting(userMoneySettingParam.getMinExpandSetting()*100);
        userMoneySettingParam.setMaxRebateSetting(userMoneySettingParam.getMaxRebateSetting()*100);
        userMoneySettingParam.setMinRebateSetting(userMoneySettingParam.getMinRebateSetting()*100);
        this.userMoneySettingService.update(userMoneySettingParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author jj
     * @Date 2019-12-23
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(UserMoneySettingParam userMoneySettingParam) {
        this.userMoneySettingService.delete(userMoneySettingParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author jj
     * @Date 2019-12-23
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(UserMoneySettingParam userMoneySettingParam) {
        UserMoneySetting detail = this.userMoneySettingService.getById(userMoneySettingParam.getId());
        return ResponseData.success(detail);
    }


    /**
     * 查看详情接口
     *
     * @author jj
     * @Date 2019-12-23
     */
    @ApiOperation("最低金额")
    @RequestMapping(value = "/appDetail",method = RequestMethod.POST)
    @ResponseBody
    public ResponseData appDetail() {
        UserMoneySetting detail = this.userMoneySettingService.getOne(null);
        return detail==null? ResponseData.error("暂无数据") : ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author jj
     * @Date 2019-12-23
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(UserMoneySettingParam userMoneySettingParam) {
        return this.userMoneySettingService.findPageBySpec(userMoneySettingParam);
    }

}


